package com.code.translate.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author ggh
 * @date 2022/7/14
 */
public class PatternUtils {
    private static final String urlEncoderRegex = "[#”%<>\\[\\]{}|\\^`&/:;=?@\\u4e00-\\u9fa5]";

    private PatternUtils() {
    }

    public static String regex(String source, String regex) {
        Pattern pattern = Pattern.compile(regex);

        Matcher matcher = pattern.matcher(source);
        if (matcher.find()) {
            return matcher.group(1);
        }
        return null;
    }

    public static boolean match(String source, String regex) {
        Pattern pattern = Pattern.compile(regex);

        Matcher matcher = pattern.matcher(source);
        return matcher.find();
    }

    public static boolean urlEncoderMatch(String source) {
        return match(source, urlEncoderRegex);
    }

    public static void main(String[] args) {
        System.out.println(regex("1", "(.*)/-/tree/"));
    }
}
